home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ALPH.{_4 / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  10KB  |  310 lines

  1. #ifndef __ALPHA_SYSTEM_H
  2. #define __ALPHA_SYSTEM_H
  3.  
  4. #include <asm/pal.h>
  5. #include <asm/page.h>
  6.  
  7. /*
  8.  * System defines.. Note that this is included both from .c and .S
  9.  * files, so it does only defines, not any C code.
  10.  */
  11.  
  12. /*
  13.  * We leave one page for the initial stack page, and one page for
  14.  * the initial process structure. Also, the console eats 3 MB for
  15.  * the initial bootloader (one of which we can reclaim later).
  16.  * With a few other pages for various reasons, we'll use an initial
  17.  * load address of PAGE_OFFSET+0x310000UL
  18.  */
  19. #define BOOT_PCB    0x20000000
  20. #define BOOT_ADDR    0x20000000
  21. /* Remove when official MILO sources have ELF support: */
  22. #define BOOT_SIZE    (16*1024)
  23.  
  24. #define KERNEL_START    (PAGE_OFFSET+0x300000)
  25. #define SWAPPER_PGD    (PAGE_OFFSET+0x300000)
  26. #define INIT_STACK    (PAGE_OFFSET+0x302000)
  27. #define EMPTY_PGT    (PAGE_OFFSET+0x304000)
  28. #define EMPTY_PGE    (PAGE_OFFSET+0x308000)
  29. #define ZERO_PGE    (PAGE_OFFSET+0x30A000)
  30.  
  31. #define START_ADDR    (PAGE_OFFSET+0x310000)
  32.  
  33. #ifndef __ASSEMBLY__
  34.  
  35. /*
  36.  * This is the logout header that should be common to all platforms
  37.  * (assuming they are running OSF/1 PALcode, I guess).
  38.  */
  39. struct el_common {
  40.     unsigned int    size;        /* size in bytes of logout area */
  41.     int        sbz1    : 30;    /* should be zero */
  42.     int        err2    :  1;    /* second error */
  43.     int        retry    :  1;    /* retry flag */
  44.     unsigned int    proc_offset;    /* processor-specific offset */
  45.     unsigned int    sys_offset;    /* system-specific offset */
  46.     unsigned long    code;        /* machine check code */
  47. };
  48.  
  49. /* Machine Check Frame for uncorrectable errors (Large format)
  50.  *      --- This is used to log uncorrectable errors such as
  51.  *          double bit ECC errors.
  52.  *      --- These errors are detected by both processor and systems.
  53.  */
  54. struct el_common_EV5_uncorrectable_mcheck {
  55.         unsigned long   shadow[8];        /* Shadow reg. 8-14, 25           */
  56.         unsigned long   paltemp[24];      /* PAL TEMP REGS.                 */
  57.         unsigned long   exc_addr;         /* Address of excepting instruction*/
  58.         unsigned long   exc_sum;          /* Summary of arithmetic traps.   */
  59.         unsigned long   exc_mask;         /* Exception mask (from exc_sum). */
  60.         unsigned long   pal_base;         /* Base address for PALcode.      */
  61.         unsigned long   isr;              /* Interrupt Status Reg.          */
  62.         unsigned long   icsr;             /* CURRENT SETUP OF EV5 IBOX      */
  63.         unsigned long   ic_perr_stat;     /* I-CACHE Reg. <11> set Data parity
  64.                                                          <12> set TAG parity*/
  65.         unsigned long   dc_perr_stat;     /* D-CACHE error Reg. Bits set to 1:
  66.                                                      <2> Data error in bank 0
  67.                                                      <3> Data error in bank 1
  68.                                                      <4> Tag error in bank 0
  69.                                                      <5> Tag error in bank 1 */
  70.         unsigned long   va;               /* Effective VA of fault or miss. */
  71.         unsigned long   mm_stat;          /* Holds the reason for D-stream 
  72.                                              fault or D-cache parity errors */
  73.         unsigned long   sc_addr;          /* Address that was being accessed
  74.                                              when EV5 detected Secondary cache
  75.                                              failure.                 */
  76.         unsigned long   sc_stat;          /* Helps determine if the error was
  77.                                              TAG/Data parity(Secondary Cache)*/
  78.         unsigned long   bc_tag_addr;      /* Contents of EV5 BC_TAG_ADDR    */
  79.         unsigned long   ei_addr;          /* Physical address of any transfer
  80.                                              that is logged in EV5 EI_STAT */
  81.         unsigned long   fill_syndrome;    /* For correcting ECC errors.     */
  82.         unsigned long   ei_stat;          /* Helps identify reason of any 
  83.                                              processor uncorrectable error
  84.                                              at its external interface.     */
  85.         unsigned long   ld_lock;          /* Contents of EV5 LD_LOCK register*/
  86. };
  87.  
  88.  
  89. extern void wrent(void *, unsigned long);
  90. extern void wrkgp(unsigned long);
  91. extern void wrusp(unsigned long);
  92. extern unsigned long rdusp(void);
  93. extern unsigned long rdmces (void);
  94. extern void wrmces (unsigned long);
  95. extern unsigned long whami(void);
  96. extern void wripir(unsigned long);
  97.  
  98. extern void halt(void) __attribute__((noreturn));
  99.  
  100. #define switch_to(prev,next) do {                    \
  101.     current = next;                            \
  102.     alpha_switch_to((unsigned long) ¤t->tss - IDENT_ADDR);    \
  103. } while (0)
  104.  
  105. extern void alpha_switch_to(unsigned long pctxp);
  106.  
  107. #define mb() \
  108. __asm__ __volatile__("mb": : :"memory")
  109.  
  110. #define rmb() \
  111. __asm__ __volatile__("mb": : :"memory")
  112.  
  113. #define wmb() \
  114. __asm__ __volatile__("wmb": : :"memory")
  115.  
  116. #define imb() \
  117. __asm__ __volatile__ ("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
  118.  
  119. #define draina() \
  120. __asm__ __volatile__ ("call_pal %0 #draina" : : "i" (PAL_draina) : "memory")
  121.  
  122.  
  123. static inline unsigned long 
  124. wrperfmon(unsigned long perf_fun, unsigned long arg)
  125. {
  126.           register unsigned long __r0 __asm__("$0");
  127.       register unsigned long __r16 __asm__("$16");
  128.       register unsigned long __r17 __asm__("$17");
  129.       __r16 = perf_fun;
  130.       __r17 = arg;
  131.       __asm__ __volatile__(
  132.           "call_pal %1"
  133.           : "=r"(__r0)
  134.           : "i"(PAL_wrperfmon), "r"(__r16), "r"(__r17)
  135.           : "$1", "$22", "$23", "$24", "$25", "$26");
  136.       return __r0;
  137. }
  138.  
  139.  
  140. #define call_pal1(palno,arg)                        \
  141. ({                                    \
  142.     register unsigned long __r0 __asm__("$0");            \
  143.     register unsigned long __r16 __asm__("$16"); __r16 = arg;    \
  144.     __asm__ __volatile__(                        \
  145.         "call_pal %3 #call_pal1"                \
  146.         :"=r" (__r0),"=r" (__r16)                \
  147.         :"1" (__r16),"i" (palno)                \
  148.         :"$1", "$22", "$23", "$24", "$25", "memory");        \
  149.     __r0;                                \
  150. })
  151.  
  152. #define getipl()                            \
  153. ({                                    \
  154.     register unsigned long r0 __asm__("$0");            \
  155.     __asm__ __volatile__(                        \
  156.         "call_pal %1 #getipl"                    \
  157.         :"=r" (r0)                        \
  158.         :"i" (PAL_rdps)                        \
  159.         :"$1", "$16", "$22", "$23", "$24", "$25", "memory");    \
  160.     r0;                                \
  161. })
  162.  
  163. #define setipl(ipl)                            \
  164. ({                                    \
  165.     register unsigned long __r16 __asm__("$16"); __r16 = (ipl);    \
  166.     __asm__ __volatile__(                        \
  167.         "call_pal %2 #setipl"                    \
  168.         :"=r" (__r16)                        \
  169.         :"0" (__r16),"i" (PAL_swpipl)                \
  170.         :"$0", "$1", "$22", "$23", "$24", "$25", "memory");    \
  171. })
  172.  
  173. #define swpipl(ipl)                        \
  174. ({                                \
  175.     register unsigned long __r0 __asm__("$0");        \
  176.     register unsigned long __r16 __asm__("$16") = (ipl);    \
  177.     __asm__ __volatile__(                    \
  178.         "call_pal %3 #swpipl"                \
  179.         :"=r" (__r0),"=r" (__r16)            \
  180.         :"1" (__r16),"i" (PAL_swpipl)            \
  181.         :"$1", "$22", "$23", "$24", "$25", "memory");    \
  182.     __r0;                            \
  183. })
  184.  
  185. #define __cli()            setipl(7)
  186. #define __sti()            setipl(0)
  187. #define __save_flags(flags)    ((flags) = getipl())
  188. #define __save_and_cli(flags)    ((flags) = swpipl(7))
  189. #define __restore_flags(flags)    setipl(flags)
  190.  
  191. #ifdef __SMP__
  192.  
  193. extern int global_irq_holder;
  194.  
  195. #define save_and_cli(flags)     (save_flags(flags), cli())
  196.  
  197. extern void __global_cli(void);
  198. extern void __global_sti(void);
  199. extern unsigned long __global_save_flags(void);
  200. extern void __global_restore_flags(unsigned long flags);
  201.  
  202. #define cli()                   __global_cli()
  203. #define sti()                   __global_sti()
  204. #define save_flags(flags)    ((flags) = __global_save_flags())
  205. #define restore_flags(flags)    __global_restore_flags(flags)
  206.  
  207. #else /* __SMP__ */
  208.  
  209. #define cli()            __cli()
  210. #define sti()            __sti()
  211. #define save_flags(flags)    __save_flags(flags)
  212. #define save_and_cli(flags)    __save_and_cli(flags)
  213. #define restore_flags(flags)    __restore_flags(flags)
  214.  
  215. #endif /* __SMP__ */
  216.  
  217. /*
  218.  * TB routines..
  219.  */
  220. #define __tbi(nr,arg,arg1...)                    \
  221. ({                                \
  222.     register unsigned long __r16 __asm__("$16") = (nr);    \
  223.     register unsigned long __r17 __asm__("$17"); arg;    \
  224.     __asm__ __volatile__(                    \
  225.         "call_pal %3 #__tbi"                \
  226.         :"=r" (__r16),"=r" (__r17)            \
  227.         :"0" (__r16),"i" (PAL_tbi) ,##arg1        \
  228.         :"$0", "$1", "$22", "$23", "$24", "$25");    \
  229. })
  230.  
  231. #define tbi(x,y)    __tbi(x,__r17=(y),"1" (__r17))
  232. #define tbisi(x)    __tbi(1,__r17=(x),"1" (__r17))
  233. #define tbisd(x)    __tbi(2,__r17=(x),"1" (__r17))
  234. #define tbis(x)        __tbi(3,__r17=(x),"1" (__r17))
  235. #define tbiap()        __tbi(-1, /* no second argument */)
  236. #define tbia()        __tbi(-2, /* no second argument */)
  237.  
  238. /*
  239.  * Give prototypes to shut up gcc.
  240.  */
  241. extern __inline__ unsigned long xchg_u32(volatile int *m, unsigned long val);
  242. extern __inline__ unsigned long xchg_u64(volatile long *m, unsigned long val);
  243.  
  244. extern __inline__ unsigned long xchg_u32(volatile int *m, unsigned long val)
  245. {
  246.     unsigned long dummy;
  247.  
  248.     __asm__ __volatile__(
  249.     "1:    ldl_l %0,%2\n"
  250.     "    bis $31,%3,%1\n"
  251.     "    stl_c %1,%2\n"
  252.     "    beq %1,2f\n"
  253.     ".section .text2,\"ax\"\n"
  254.     "2:    br 1b\n"
  255.     ".previous"
  256.     : "=&r" (val), "=&r" (dummy), "=m" (*m)
  257.     : "rI" (val), "m" (*m));
  258.  
  259.     return val;
  260. }
  261.  
  262. extern __inline__ unsigned long xchg_u64(volatile long * m, unsigned long val)
  263. {
  264.     unsigned long dummy;
  265.  
  266.     __asm__ __volatile__(
  267.     "1:    ldq_l %0,%2\n"
  268.     "    bis $31,%3,%1\n"
  269.     "    stq_c %1,%2\n"
  270.     "    beq %1,2f\n"
  271.     ".section .text2,\"ax\"\n"
  272.     "2:    br 1b\n"
  273.     ".previous"
  274.     : "=&r" (val), "=&r" (dummy), "=m" (*m)
  275.     : "rI" (val), "m" (*m));
  276.  
  277.     return val;
  278. }
  279.  
  280. /*
  281.  * This function doesn't exist, so you'll get a linker error
  282.  * if something tries to do an invalid xchg().
  283.  *
  284.  * This only works if the compiler isn't horribly bad at optimizing.
  285.  * gcc-2.5.8 reportedly can't handle this, but as that doesn't work
  286.  * too well on the alpha anyway..
  287.  */
  288. extern void __xchg_called_with_bad_pointer(void);
  289.  
  290. static __inline__ unsigned long
  291. __xchg(unsigned long x, volatile void * ptr, int size)
  292. {
  293.     switch (size) {
  294.         case 4:
  295.             return xchg_u32(ptr, x);
  296.         case 8:
  297.             return xchg_u64(ptr, x);
  298.     }
  299.     __xchg_called_with_bad_pointer();
  300.     return x;
  301. }
  302.  
  303. #define xchg(ptr,x) \
  304.   ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  305. #define tas(ptr) (xchg((ptr),1))
  306.  
  307. #endif /* __ASSEMBLY__ */
  308.  
  309. #endif
  310.